//
//  BQAlterAdressTV.m
//  BeeQuick
//
//  Created by Vivitickey on 2017/5/7.
//  Copyright © 2017年 test. All rights reserved.
//

#import "BQAlterAdressTV.h"
#import "BQAlterFirstCell.h"
#import "BQAlterSecondCell.h"
#import "BQAlterThirdCell.h"
#import "BQAdressModel.h"
#import "UIColor+HMAddition.h"
@interface BQAlterAdressTV ()

@end
static NSString *name_cell = @"name_cell";
static NSString *gender_cell = @"gender_cell";
static NSString *num_cell = @"num_cell";
static NSString *city_cell = @"city_cell";
static NSString *area_cell = @"area_cell";
static NSString *adress_cell = @"adress_cell";
static NSString *delete_cell = @"delete_cell";
@implementation BQAlterAdressTV

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationItem.title = @"修改地址";
    
    [self.tableView registerNib:[UINib nibWithNibName:@"BQAlterFirstCell" bundle:nil] forCellReuseIdentifier:name_cell];
    [self.tableView registerNib:[UINib nibWithNibName:@"BQAlterSecondCell" bundle:nil] forCellReuseIdentifier:gender_cell];
    [self.tableView registerNib:[UINib nibWithNibName:@"BQAlterFirstCell" bundle:nil] forCellReuseIdentifier:num_cell];
    [self.tableView registerNib:[UINib nibWithNibName:@"BQAlterFirstCell" bundle:nil] forCellReuseIdentifier:city_cell];
    [self.tableView registerNib:[UINib nibWithNibName:@"BQAlterFirstCell" bundle:nil] forCellReuseIdentifier:area_cell];
    [self.tableView registerNib:[UINib nibWithNibName:@"BQAlterFirstCell" bundle:nil] forCellReuseIdentifier:adress_cell];
    [self.tableView registerNib:[UINib nibWithNibName:@"BQAlterThirdCell" bundle:nil] forCellReuseIdentifier:delete_cell];

    self.tableView.tableFooterView = [UIView new];
    
    self.tableView.backgroundColor = [UIColor hm_colorWithR:239 G:239 B:239];
    UIImage *image =[UIImage imageNamed:@"v2_goback-1"];
    UIButton *btn =[[UIButton alloc]init];
    [btn  setBackgroundImage:image forState:UIControlStateNormal];
    btn.frame =CGRectMake(0, 0, 24, 24);
    
    UIBarButtonItem *button =[[UIBarButtonItem alloc]initWithCustomView:btn];
    [btn addTarget:self action:@selector(click) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem =button;
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"保存" style:UIBarButtonItemStylePlain target:nil action:nil];
    
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor lightGrayColor]];

}


-(void)click{
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section == 0) {
        return 6;
    }
    
    return 1;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section == 0 && indexPath.row == 0) {
        BQAlterFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:name_cell forIndexPath:indexPath];
        
        cell.leftLabel.text = @"联系人";
        
        cell.rightLabel.text = self.model.accept_name;
        
        return cell;
    }else if(indexPath.section == 0 && indexPath.row == 1) {
        BQAlterSecondCell *cell = [tableView dequeueReusableCellWithIdentifier:gender_cell forIndexPath:indexPath];
        
        if ([self.model.gender isEqualToString:@"1"]) {
            cell.manButton.selected = YES;
            cell.womenButton.selected = NO;
        }else{
            cell.manButton.selected = NO;
            cell.womenButton.selected = YES;
        }
        
        return cell;
    }else if(indexPath.section == 0 && indexPath.row == 2) {
        BQAlterFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:num_cell forIndexPath:indexPath];
        
        cell.leftLabel.text = @"手机号码";
        
        cell.rightLabel.text = self.model.telphone;
        
        return cell;
    }else if(indexPath.section == 0 && indexPath.row == 3) {
        BQAlterFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:city_cell forIndexPath:indexPath];
        
        cell.leftLabel.text = @"所在城市";
        
        cell.rightLabel.text = self.model.city_name;
        
        return cell;
    }else if(indexPath.section == 0 && indexPath.row == 4) {
        BQAlterFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:area_cell forIndexPath:indexPath];
        
        cell.leftLabel.text = @"所在地区";
        
        NSString *string = self.model.address;
        
        NSArray *array = [string componentsSeparatedByString:@" "];
        
        cell.rightLabel.text = [NSString stringWithFormat:@"%@",array[0]];
        
        return cell;
    }else if(indexPath.section == 0 && indexPath.row == 5) {
        BQAlterFirstCell *cell = [tableView dequeueReusableCellWithIdentifier:adress_cell forIndexPath:indexPath];
        
        cell.leftLabel.text = @"详细地址";
        
        NSString *string = self.model.address;
        
        NSArray *array = [string componentsSeparatedByString:@" "];
        
        cell.rightLabel.text = [NSString stringWithFormat:@"%@",array[1]];
        
        return cell;
    }else{
        BQAlterThirdCell *cell = [tableView dequeueReusableCellWithIdentifier:delete_cell forIndexPath:indexPath];
        
        return cell;
    }
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 10;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //消除cell选择痕迹
    [self performSelector:@selector(deselect) withObject:nil afterDelay:0.5f];
    
    
    
    
}
- (void)deselect
{
    [self.tableView deselectRowAtIndexPath:[self.tableView indexPathForSelectedRow] animated:YES];
}

@end
